@extends('admin.common.common')

@section('head')
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <link rel="stylesheet" href="/admin/static/h-ui.admin/css/bootstrap.min.css">
@endsection



@section('body')
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 预约中心 <span class="c-gray en">&gt;</span> 预约管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
    <div class="pd-20">
        <div class="text-c">
            <form action="{{route('admin.notice.index')}}">搜索：
                <input type="text" class="input-text"  style="width:250px" placeholder="请输入" id="" name="keyword">
                <button type="submit" class="btn btn-success"><i class="icon-search"></i> 搜预约</button>
            </form>
        </div>
        <div class="cl pd-5 bg-1 bk-gray mt-20">
    <span class="l">
        <a href="javascript:;" class="btn btn-danger radius deleteAll"><i class="icon-trash"></i> 批量删除</a>
    <a href="{{route('admin.notice.create')}}" class="btn btn-primary radius"><i class="icon-plus"></i> 添加预约</a></span>
            <span class="r">共有数据：<strong>  </strong> 条</span>
        </div>
        <table class="table table-border table-bordered table-hover table-bg table-sort">
            <thead>
            <tr class="text-c">
                <th width="25"><input type="checkbox" name="checkall" value=""></th>
                <th width="80">ID</th>
                <th width="100">房东id</th>
                <th width="100">租客id</th>
                <th width="40">预约时间</th>
                <th width="90">内容</th>
                <th width="150">状态</th>
                <th width="">添加时间</th>
                <th width="100">操作</th>
            </tr>
            </thead>
            <tbody>
            @foreach($data as $key=>$val)
                <tr>
                    <td><input type="checkbox" value="{{$val->id}}" name="ids[]"></td>
                    <td>{{$val->id}}</td>
                    <td>{{$val->fangowner_id}}</td>
                    <td>{{$val->renting_id}}</td>
                    <td>{{$val->dtime}}</td>
                    <td>{{$val->cnt}}</td>
                    <td>
                        @if($val->status ==0)
                            <span class="btn btn-primary change" notice_id="{{$val->id}}" status="0" onclick="statusChange(this)">未看</span>
                        @else
                            <span class="btn btn-warning change" notice_id="{{$val->id}}"  status="1" onclick="statusChange(this)">已看</span>
                        @endif
                    </td>
                    <td>{{$val->created_at}}</td>
                    <td class="f-14 user-manage" style="width: 200px">
                        <a title="编辑" href="javascript:;" class="btn btn-success" style="text-decoration:none"><i class="icon-edit">编辑</i></a>
                        <a title="删除" href="{{route('admin.notice.destroy',$val)}}" class="btn btn-danger" style="text-decoration:none"><i class="icon-edit">删除</i></a>
                        <a title="查看图片" onclick="layer_show('查看图片','{{route('admin.fang.show',$val)}}',500,500)" href="javascript:;" class="btn btn-warning" style="text-decoration:none;color: black"><i class="icon-trash">查看图片</i></a>
                    </td>
                </tr>

            @endforeach
            </tbody>
        </table>

        {{$data->links()}}


        <div id="pageNav" class="pageNav"></div>
    </div>

@endsection


@section('js')
    <script src="/admin/static/h-ui.admin/js/layer/layer.js"></script>

    <script>
        //全选全不选
        $("input[name='checkall']").click(function () {
            $("input[name='ids[]']").prop('checked',$("input[name='checkall']").prop('checked'))
        })

        //删除一条数据
        $('.btn-danger').click(function () {
            let url = $(this).attr('href')

            $.ajax({
                url:url,
                data:{
                    _token:"{{csrf_token()}}",
                },
                type:"delete",
                success:res=>{
                    if(res.error_code == 0){
                        layer.msg(res.msg,{icon:1,time:1000},function(){
                            history.go(0);
                        })
                    }
                }
            })
            return false
        })

        function statusChange(obj) {
            let id = $(obj).attr('notice_id');
            let status = $(obj).attr('status');

            $.ajax({
                url: "{{route('admin.notice.status')}}",
                data:{
                    _token:"{{csrf_token()}}",
                    id,
                    status
                },
                type: "put",
                success:res=>{
                    if(res.error_code == 0){
                        if(status == 0){
                            $(obj).attr('status',1)
                            $(obj).removeClass('btn-primary').addClass('btn-warning')
                            $(obj).html('已看')
                        }else{
                            $(obj).attr('status',0)
                            $(obj).removeClass('btn-warning').addClass('btn-primary')
                            $(obj).html('未看')
                        }

                    }
                }
            })
        }

    </script>
@endsection
